<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>拾取对象pick</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        #box {
            height: 100px;
            text-align: center;
        }

        #box>p {
            text-align: left;
        }

        #box>p:nth-child(1)>span {
            color: sandybrown;
        }

        #box>p:nth-child(2),
        #box>p:nth-child(3) {
            padding-left: 50px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div id="box">
            <p><span>提示：</span>打开控制台</p>
            <p>1、点击楼宇，查看返回值</p>
            <p>2、点击空白区域，查看返回值</p>
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']

        const { PickedInfo } = XE2["xe2-base-objects"]
        const objm = new ESObjectsManager();
        window.g_objm = objm;

        // 监听视口创建完成事件
        objm.viewerCreatedEvent.don((viewer) => {
            /**
             * 
             * pick(screenPosition, attachedInfo)：拾取方法
             *  参数1：screenPosition 像素点位置
             *  参数2：attachedInfo 附加信息，【可选，默认undefined】（场景对象pickedEvent被拾取的时候用来区分是哪些自定义事件触发的）
             *  
            */

            // 鼠标click事件的时候,定义自定义的pick事件
            viewer.clickEvent.don((e) => {
                viewer.pick(e.screenPosition, 'customPick').then(res => {
                    // 全局拾取对象
                    if (res && res.sceneObject) {
                        console.log("拾取到的es对象", res.sceneObject)
                    }
                })
            })
        })

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            "domid": document.getElementById("app")
        })
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                viewer.flyIn([116.39947309868032, 39.90592001431495, 334.38857241671485], [121.37477595297989, -33.67659827219708, 359.9997913701847], 3)
            }
        })

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        // 创建一个ESGltfModel对象
        const { ESGltfModel } = XE2['esobjs-xe2-plugin-main']
        const model = objm.createSceneObject(ESGltfModel)
        model.position = [116.404, 39.904, 0]


    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>